package com.foreknow.eldclient.dao;

import com.foreknow.eldclient.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DeliveryAddressMapper {
    /**
     * 通过用户ID列出所有配送地址
     * @param userId
     * @return
     * @throws Exception
     */
    @Select("select * from deliveryAddress where userId=#{userId} order by daId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) throws Exception;

    /**
     * 插入一条地址
     * @param deliveryAddress
     * @return
     * @throws Exception
     */
    @Insert("insert into deliveryAddress values(null,#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception;

    /**
     * 通过送货地址编号查询配送信息
     * @param daId
     * @return
     * @throws Exception
     */
    @Select("select * from deliveryAddress where daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(Integer daId) throws Exception;

    /**
     * 根据送货地址编号修改配送信息
     * @param deliveryAddress
     * @return
     * @throws Exception
     */
    @Update("update deliveryAddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address} where daId=#{daId}")
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception;

    /**
     * 根据送货地址编号删除配送信息
     * @param daId
     * @return
     * @throws Exception
     */
    @Delete("delete from deliveryAddress where daId=#{daId}")
    public int removeDeliveryAddress(Integer daId) throws Exception;


}
